package com.leyou.auth.interceptors;

import com.leyou.auth.config.JwtProperties;
import com.leyou.auth.task.PrivilegeTokenHolder;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.stereotype.Component;

@Component
@EnableConfigurationProperties(JwtProperties.class)
public class PrivilegeInterceptor implements RequestInterceptor{

    @Autowired
    private JwtProperties prop;

    @Autowired
    private PrivilegeTokenHolder tokenHolder;

    @Override
    public void apply(RequestTemplate requestTemplate) {

        // 获取token
        String token = tokenHolder.getToken();
        // 给请求添加头信息
        requestTemplate.header(prop.getApp().getHeaderName(), token);
    }
    }

